package com.hunan.yllxy.repostitory.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hunan.yllxy.repostitory.entity.PowerStation;
import com.hunan.yllxy.repostitory.mapper.PowerStationMapper;
import com.hunan.yllxy.repostitory.dao.PowerStationDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hunan.yllxy.util.PageResultUtils;
import com.hunan.yllxy.vo.PageQuery;
import com.hunan.yllxy.vo.PageResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘华
 * @since 2025-06-20
 */
@Service
public class PowerStationDaoImpl extends ServiceImpl<PowerStationMapper, PowerStation> implements PowerStationDao {
    @Override
    public Page<PowerStation> powerStationQuery(PageQuery pageQuery) {
        LambdaQueryWrapper<PowerStation> query = Wrappers.lambdaQuery(this
                .entityClass);
        query.orderByDesc(PowerStation::getUpdateTime);
        Page page = PageResultUtils.getPage(pageQuery, this.entityClass);
        return baseMapper.selectPage(page,query);
    }

    @Override
    public Page<PowerStation> powerStationQueryPublish(PageQuery pageQuery) {
        LambdaQueryWrapper<PowerStation> powerStationLambdaQueryWrapper = Wrappers.lambdaQuery(this
                .entityClass);
        powerStationLambdaQueryWrapper.eq(PowerStation::getPublishState,1);
        powerStationLambdaQueryWrapper.orderByDesc(PowerStation::getUpdateTime);
        Page page = PageResultUtils.getPage(pageQuery, this.entityClass);
        return baseMapper.selectPage(page,powerStationLambdaQueryWrapper);
    }
}
